/**
 * 根据key进行数据查询
 * @param {*} db    数据库名称
 * @param {*} storeName  表名称
 * @param {*} key 查询字段 openDB 里面 keyPath：xxx 的主键对应的值
 * @returns
 */
export function getDataById(db, storeName, key) {
  return new Promise((resolve, reject) => {
    const transaction = db.transaction([storeName]); // 事务
      const objectStore = transaction.objectStore(storeName); // 仓库对象
    const request = objectStore.get(key);

    request.onerror = function (event) {
      reject(event);
    };

    request.onsuccess = function (event) {
      resolve(request.result);
    };
  });
}
